package com.dujiawei.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.HashMap;
import java.util.Map;

public class JSONResult {

    public static String fillResultString(Integer status, String message, Object result) {

        Gson gson = new GsonBuilder().enableComplexMapKeySerialization().serializeNulls().disableHtmlEscaping().create();

        Map map = new HashMap() {{
            put("status", status);
            put("message", message);
            put("result", result);
        }};
        System.out.println(map);
        //String s = gson.toJson(map);
        ObjectMapper objectMapper = new ObjectMapper();
        String s = null;
        try {
            s = objectMapper.writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        System.out.println(s);
        return s;
    }
}